package com.filesystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.filesystem.file.entity.Files;
import com.filesystem.file.service.impl.FileServiceImpl;
import com.filesystem.utils.Result;
//import com.filesystem.utils.ResultUtil;
import com.filesystem.utils.ResultUtil;
import com.filesystem.utils.Results;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author JayZhou
 * @version 1.0
 * @description: TODO
 * @date 2021/6/8 23:26
 */

@Controller
public class indexController {

    @Autowired
    FileServiceImpl fileService;

    @Autowired
    HttpServletRequest request;

    /**
     *  首页视图
     * @return 返回首页视图
     */
     @RequestMapping({"/","index","main"})
      public String index(Model model){
         List<Files> list = fileService.list(null);
         model.addAttribute("list",list);
         return "index";
      }

    /**
     *  登录视图
     * @return 登录视图
     */
      @RequestMapping({"/login"})
      public String login(){
         return "/login";
      }


    @RequestMapping("/filesList/page")
    @ResponseBody
    public Results page(@RequestParam("page") int page , @RequestParam("limit") int limit ,
                        @RequestParam( required = false ) String filename ,
                        @RequestParam(required = false) String username ){
        Page<Files> select = fileService.select(page, limit,filename,username);
        List<Files> data = select.getRecords();
        long total = select.getTotal();
        return ResultUtil.success(Math.toIntExact(total), data);
    }




}
